class Solution
{
public:
    int maximumPrimeDifference(vector<int> &nums)
    {
        vector<int> isPrime(105, 1);
        isPrime[0] = isPrime[1] = 0;
        for (int i = 2; i < 105; ++i)
        {
            if (isPrime[i])
            {
                for (int j = i * i; j < 105; j += i)
                {
                    isPrime[j] = 0;
                }
            }
        }

        int first = -1;
        int last = -1;
        for (int i = 0; i < nums.size(); ++i)
        {
            if (isPrime[nums[i]])
            {
                if (first == -1)
                {
                    first = i;
                }
                last = i;
            }
        }
        return last - first;
    }
};